package com.csg.web.support;

import org.springframework.web.context.request.async.DeferredResult;

import java.util.HashMap;
import java.util.Map;

/**
 * 延迟结果持有者
 *
 * @author george
 */
public class DeferredResultHolder {

    /**
     * 延迟结果对象map
     */
    private static final Map<String, DeferredResult> DEFERRED_RESULT_MAP = new HashMap<>();


    /**
     * 单例模式
     */
    private DeferredResultHolder() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 添加延迟结果对象
     *
     * @param key            唯一标识
     * @param deferredResult 延迟结果对象
     */
    public static void add(String key, DeferredResult deferredResult) {
        DEFERRED_RESULT_MAP.put(key, deferredResult);
    }

    /**
     * 获取延迟结果对象
     *
     * @param key 唯一标识
     * @return 延迟结果对象
     */
    public static DeferredResult get(String key) {
        return DEFERRED_RESULT_MAP.get(key);
    }

    /**
     * 移除延迟结果对象
     *
     * @param key 唯一标识
     */
    public static void remove(String key) {
        DEFERRED_RESULT_MAP.remove(key);
    }
}
